package NG::Sys::File;
use strict;
use warnings;
use utf8;

require Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
read_int
write_int
is_proc_run
);


sub read_int {
	my $filename = shift;
	local *FILE;
	local $/;
	my $result;
	if(open FILE, $filename){
		$result = <FILE>;
		close FILE;
	}
	return 0 + ($result || 0);
}

sub write_int {
	my $filename = shift;
	my $int = shift;
	local *FILE;
	open FILE, '>', $filename or die "Cant open '$filename' $!";
	print FILE $int;
	close FILE;
}

sub is_proc_run {
	my ($pid,$filename) = @_;
	
	my $procfile = "/proc/$pid/cmdline";
	
	return 0 unless ( -e $procfile );
	return 0 unless ( $filename );
	
	local *FILE;
	local $/;
	open FILE, $procfile;
	my $str = <FILE>;
	close FILE;
	
	return $str =~ /$filename/ ? 1:0;
}



1;
